<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <link rel="stylesheet" href="../../styles/common.css" />
  <link rel="stylesheet" href="../../styles/page.css" />
  <style>
    .search-btn {
      margin-left: 20px;
    }

    .tableBar {
      justify-content: flex-start !important;
    }

    .info-box {
      margin: -15px -44px 20px;
    }

    .info-box .item-box {
      display: flex;
      height: 20px;
      line-height: 20px;
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      text-align: left;
      margin-bottom: 14px;
    }

    .info-box .item-box:last-child {
      margin-bottom: 0;
    }

    .info-box .item-box .label {
      width: 96px;
    }

    .info-box .item-box .des {
      flex: 1;
      color: #333333;
    }
  </style>
</head>

<body>
  <div class="dashboard-container" id="order-app" v-loading="loading">
    <div class="container">
      <!-- 搜索项 -->
      <div class="tableBar">
        <el-date-picker v-model="orderTime" clearable value-format="yyyy-MM-dd HH:mm:ss" type="datetimerange"
          placeholder="选择日期" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" style="width: 400px;margin-left: 20px;"></el-date-picker>
        <el-button type="primary" class="search-btn" @click="init">查询</el-button>
      </div>

      <div id="main" style="width: 1000px;height:500px;margin-top: 30px;text-align: center;"></div>
    </div>

  </div>
  <script src="../../js/echarts.js"></script>
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="../../plugins/vue/vue.js"></script>
  <!-- 引入组件库 -->
  <script src="../../plugins/element-ui/index.js"></script>
  <!-- 引入axios -->
  <script src="../../plugins/axios/axios.min.js"></script>
  <script src="../../js/request.js"></script>
  <script src="../../api/order.js"></script>
  <!-- 引入echarts -->
  <script src="../../api/echarts.js"></script>
  <script>
    new Vue({
      el: '#order-app',
      data() {
        return {
          orderTime: '',
          beginTime: '',
          endTime: '',
          loading: false,
          myChart: null,
          msg: [],
          money:''

        }
      },
      computed: {

      },
      watch:{
        orderTime (val) {
          if (val && val.length >= 2) {
            this.beginTime = val[0]
            this.endTime = val[1]
          } else {
            this.beginTime = ''
            this.endTime = ''
          }
        }
      },
      created() {

      },
      mounted() {
        // this.loading = false
        //加载餐品售卖信息
        this.start2();
      },
      methods: {
        start1() {
          console.log("开启绘图")
          console.log(this.msg)
          const option= {
            title: {
              text: '售卖统计表',
              subtext: this.money,
              left: 'center'
            },
            tooltip: {
              trigger: 'item'
            },
            legend: {
              orient: 'vertical',
                      left: 'left'
            },
            series: [
              {
                name: '商品',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                data: this.msg,
                emphasis: {
                  itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                  }
                },
                label: {
                  show: false,
                  position: 'center'
                }
              }
            ]
          }
          var chartDom = document.getElementById('main');
          this.myChart = echarts.init(chartDom);
          option && this.myChart.setOption(option);
        },

        start2() {
          getEcharts({ beginTime: this.beginTime || undefined, endTime: this.endTime || undefined }).then(res => {
            if (String(res.code) === '1') {
              console.log(res.data.money)
              this.money='总营业额'+res.data.money
                console.log(res.data.echarts)
                this.msg = res.data.echarts
              //this.option.series.data = res.data.records || []
              this.start1()
            }
          }).catch(err => {
            this.$message.error('请求出错了：' + err)
          })

        },
        async init() {
          this.start2();
        },
      }
    })
  </script>
</body>

</html>